package thread;

import java.util.concurrent.atomic.AtomicInteger;

public class leetCode1114 {

    private AtomicInteger a = new AtomicInteger();
    private AtomicInteger b = new AtomicInteger();

    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        a.incrementAndGet();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        while (a.get() != 1){
            // wait
        }
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        b.incrementAndGet();
    }

    public void third(Runnable printThird) throws InterruptedException {
        while (b.get() != 1){
            // wait
        }
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
}
